home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 …ember: Reference Library / Dev.CD Dec 00 RL Disk 1.toast / mac / Technical Documentation / Develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15.sea / Scriptable Database 1.0a15 / Foundation / AbstractScriptableObject.h / AbstractScriptableObject.h
Encoding:
C/C++ Source or Header  |  1996-02-20  |  17.1 KB  |  386 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        AbstractScriptableObject.h
  3.  
  4.     Contains:    Abstract base class that supports scriptability in objects
  5.  
  6.     Written by:    Andy Nicholas, Greg Anderson, Tom Conrad, Chris Bingham, Georgiann Puckett
  7.  
  8.     Copyright:    © 1994-1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.         <20>     9/26/95    pco        
  11.  
  12. */
  13.  
  14. #ifndef __ABSTRACTSCRIPTABLEOBJECT__
  15. #define __ABSTRACTSCRIPTABLEOBJECT__
  16. #define AbstractScriptableObject_h
  17.  
  18. //
  19. // MoreAEM.h is needed because methods defined in this
  20. // file take TDescriptors as pass-by-value parameters,
  21. // which requires the complete definition of the class
  22. // TDescriptor.
  23. // 
  24. #include "MoreAEM.h"
  25.  
  26. //
  27. // Object.h is needed because TObject is the base class of
  28. // TAbstractScriptableObject, and for the DeclareClassData macros.
  29. //
  30. #include "Object.h"
  31.  
  32. //
  33. // TAbstractSearchSpec represents a specification for a
  34. // test to be done in a search (e.g. during whose clause resolution).
  35. // TSearchSpecList is, of course, a list of TAbstractSearchSpecs.
  36. //
  37. class TAbstractSearchSpec;
  38. template <class T> class AListOf;
  39.  
  40. //
  41. // Abstract references are 'abreviated' representations of some
  42. // other scriptable object
  43. //
  44. class TAbstractReference;
  45.  
  46. //
  47. // An abstract object iterator knows how to iterate over some
  48. // list of TAbstractScriptableObjects.
  49. //
  50. class TAbstractObjectIterator;
  51.  
  52. //
  53. // A list of TAbstractScriptableObjects
  54. //
  55. class TAbstractScriptableObject;
  56. template <class T> class AListOf;
  57.  
  58. //
  59. // An object that represents data to compare; could be literal
  60. // data, or a description of a property of some object.
  61. //
  62. class TComparisonOperand;
  63.  
  64.  
  65. #define clScriptableObject        2
  66. #define clDesignator            3
  67. #define clProperty                4
  68. #define clGenericProperty        5
  69. #define clProxyToken            6
  70. #define clMarkToken                7
  71. #define clEveryItem                8
  72. #define clEntireContents        9
  73. // #define clCollectorBehavior        11
  74. #define clSearchSpec            12
  75. #define clLogicalSearchSpec        13
  76. #define clGenericSearchSpec        14
  77. #define clSearchEngine            15
  78.  
  79. #define kObjectRecordedClass true
  80.  
  81. //
  82. // There are three types of mark tokens:
  83. //
  84. //        kSingleItemOrCollection - example: the selection--but the selection is not
  85. //                                    a mark token, so this mark type is never used.
  86. //                                    Returns either a single item or a collection of
  87. //                                    items.  Operations on the elements of the mark
  88. //                                    operate on the items in the collection.
  89. //
  90. //        kSingleItemOrUnion        - example:  access by name.  Returns either a single
  91. //                                    item or a union set of items.  Operations on
  92. //                                    the elements of the mark operate on the union of
  93. //                                    every element of every item in the set
  94. //
  95. //        kAlwaysMakeCollection    - example:  whose clauses.  Always returns a collection
  96. //                                    of items, even if there is only one item in the
  97. //                                    collection.  This is done so that the result of
  98. //                                    a whose clause is always a list, even if only one
  99. //                                    item is returned.
  100. //
  101. // Special case:
  102. //
  103. //        kPropertyUnion            - only used with collections of properties gathered
  104. //                                    from a proxy token.  Behaves like kSingleItemOrUnion,
  105. //                                    but changes behavior of best type and default type
  106. //                                    for the collection.
  107. //
  108. enum TypeOfMarkToken
  109.     {
  110.     kSingleItemOrUnion,
  111.     kSingleItemOrCollection,
  112.     kPropertyUnion,
  113.     kAlwaysMakeCollection
  114.     };
  115.  
  116.  
  117. //
  118. // The magic value kNeverCreateGenericProperty should be placed in
  119. // property tables in any instance where a generic property should
  120. // never be created.  Usually this is not needed, as the correct
  121. // property token should be created in AccessByProperty; however, in
  122. // some cases a property is constructed from the property table
  123. // without calling AccessByProperty (for example, to make a property
  124. // of a proxy token); in that case, this value will prevent the incorrect
  125. // type of property from being created.
  126. //
  127. // The magic value kDontIncludeInPropertiesProperty should be placed
  128. // in the property tables in any instance where a property is included
  129. // for definition purposes, but said property should not be part of
  130. // the "properties" property.
  131. //
  132. // These special values may be ORed together.  The low shortword of
  133. // the additional info is still usable by clients if the special values
  134. // are used.  And with 'kReservedRangeUsableByClients' to mask out
  135. // the special range when using the additional info if this is done.
  136. // If the value stored in the additional info field is less than
  137. // 0x7F000000, then the entire longword is usable by the client.
  138. //
  139. enum
  140.     {
  141.     kReservedRangeForPropertyInfo        = 0x7F000000,            // Values in the property additional info >= this value have special meanings
  142.     kReservedRangeUsableByClients        = 0x0000FFFF,            // When the reserved range is used, clients may define the short word of this property to be whatever they wish
  143.     kNeverCreateGenericBit                = 0x00800000,
  144.     kDontIncludeInPropertiesPropertyBit    = 0x00400000,
  145.     kBestTypeIsSameAsDefaultTypeBit        = 0x00200000,            // Set this bit to make BestType == DefaultType; the BestType field may then be used for something else
  146.     kNeverCreateGenericProperty            = (kReservedRangeForPropertyInfo | kNeverCreateGenericBit),
  147.     kDontIncludeInPropertiesProperty    = (kReservedRangeForPropertyInfo | kDontIncludeInPropertiesPropertyBit),
  148.     kBestTypeIsSameAsDefaultType        = (kReservedRangeForPropertyInfo | kBestTypeIsSameAsDefaultTypeBit),
  149.     
  150.     kLookupAdditionalInfo                = 0xFFFFFFFF            // This value is used internally only; don't consider it part of the API
  151.     };
  152.  
  153.  
  154. //========================================================================================
  155. //    Inline functions used by TPropertyDescription, below.
  156. //========================================================================================
  157.  
  158.  
  159. //----------------------------------------------------------------------------------------
  160. // NeverCreateGenericProperty
  161. //----------------------------------------------------------------------------------------
  162. inline Boolean NeverCreateGenericProperty(unsigned long x)
  163.     {
  164.     return (x >= kReservedRangeForPropertyInfo) && ((x & kNeverCreateGenericBit) != 0);
  165.     }
  166.  
  167. //----------------------------------------------------------------------------------------
  168. // DontIncludeInPropertiesProperty
  169. //----------------------------------------------------------------------------------------
  170. inline Boolean DontIncludeInPropertiesProperty(unsigned long x)
  171.     {
  172.     return (x >= kReservedRangeForPropertyInfo) && ((x & kDontIncludeInPropertiesPropertyBit) != 0);
  173.     }
  174.  
  175. //----------------------------------------------------------------------------------------
  176. // BestTypeIsSameAsDefaultType
  177. //----------------------------------------------------------------------------------------
  178. inline Boolean BestTypeIsSameAsDefaultType(unsigned long x)
  179.     {
  180.     return (x >= kReservedRangeForPropertyInfo) && ((x & kBestTypeIsSameAsDefaultTypeBit) != 0);
  181.     }
  182.  
  183.  
  184. //========================================================================================
  185. // CLASS TPropertyDescription
  186. //========================================================================================
  187.  
  188. class TPropertyDescription
  189.     {
  190. public:
  191.     unsigned long            fPropertyIdentifier;
  192.     unsigned long            fAdditionalInfo;
  193.     unsigned long            fDefaultType;
  194.     unsigned long            fBestType;
  195.  
  196. public:
  197.     unsigned long            PropertyIdentifier() const    { return fPropertyIdentifier; }
  198.     unsigned long            AdditionalInfo() const        { return fAdditionalInfo; }
  199.     unsigned long            DefaultType() const            { return fDefaultType; }
  200.     unsigned long            BestType() const            { return BestTypeIsSameAsDefaultType(fAdditionalInfo) ? fDefaultType : fBestType; }
  201.     unsigned long            ExtendedInfo() const        { return BestTypeIsSameAsDefaultType(fAdditionalInfo) ? fBestType : 0; }
  202.     
  203.     Boolean operator==(const TPropertyDescription& rhs)
  204.         {
  205.             return    ((this->PropertyIdentifier() == rhs.PropertyIdentifier()) &&
  206.                     (this->AdditionalInfo() == rhs.AdditionalInfo()) &&
  207.                     (this->DefaultType() == rhs.DefaultType()) &&
  208.                     (this->BestType() == rhs.BestType()));
  209.         }
  210.     Boolean operator!=(const TPropertyDescription& rhs) { return !this->operator==(rhs); }
  211.     };
  212.  
  213. //
  214. // New declare / implement macros:
  215. //
  216. #define DeclareClassData(className, superclass)                                                                        \
  217.                 static        TPropertyDescription      fPropertiesOfClass[];                                            \
  218.                 static        TClassData              fClassData;                                                        \
  219.                 typedef        superclass                Inherited;                                                        \
  220.                 virtual     const TClassData*        ClassData() const;
  221.  
  222. #ifdef DEBUG
  223.  
  224. #define ImplementClassData(className, classID)                                                                        \
  225.         const TClassData* className::ClassData() const { return &fClassData; }         \
  226.         TClassData className::fClassData = {#className, 0, classID, sizeof(className), &className::Inherited::fClassData, {sizeof(className::fPropertiesOfClass) / sizeof(TPropertyDescription), className::fPropertiesOfClass} };
  227.  
  228. #else
  229.  
  230. #define ImplementClassData(className, classID)                                                                        \
  231.         const TClassData* className::ClassData() const { return &fClassData; }         \
  232.         TClassData className::fClassData = {0, classID, sizeof(className), &className::Inherited::fClassData, {sizeof(className::fPropertiesOfClass) / sizeof(TPropertyDescription), className::fPropertiesOfClass} };
  233.  
  234. #endif
  235.  
  236.  
  237. class TAETransaction;
  238. class TAbstractCollector;
  239.  
  240. //========================================================================================
  241. //    CLASS TAbstractScriptableObject
  242. //========================================================================================
  243.  
  244. class TAbstractScriptableObject : public TObject
  245.     {
  246. public:
  247.     DeclareClassData(TAbstractScriptableObject, TObject);
  248.  
  249.                                         TAbstractScriptableObject();
  250.     virtual                                ~TAbstractScriptableObject();
  251.     void                                IAbstractScriptableObject();
  252.  
  253.     // virtual TAbstractScriptableObject&    operator=(const TAbstractScriptableObject& rhs);
  254.     virtual Boolean                        IsDesignator();
  255.     virtual void                        DisposeDesignator();
  256.     virtual TAbstractScriptableObject*    CloneDesignator();
  257.     
  258.     // Methods that determine class membership
  259.     
  260.     virtual DescType                    ObjectClass(const TAETransaction& t, Boolean recordedClass = false); // make this pure-virutal later = 0;
  261.     virtual Boolean                        DerivedFromOSLClass(const TAETransaction& t, DescType objectClass);
  262.  
  263.     // 'Exists' is almost always true, but proxies may need to override & return 'false' in some instances
  264.     // (for example, a token for an empty selection, or a token for a closed window would both return 'false')
  265.     
  266.     virtual Boolean                        Exists(const TAETransaction& transaction);
  267.  
  268.     // Accessors:
  269.     
  270.     virtual TAbstractScriptableObject*    ParentObject(const TAETransaction& transaction);
  271.     virtual TAbstractObjectIterator*    ElementIterator(const TAETransaction&);
  272.     
  273.     long                                CountElements(const TAETransaction& t, DescType classToCount = typeWildCard);
  274.     TAbstractScriptableObject*            AccessByIndex(const TAETransaction& t, DescType desiredClass, long index);
  275.     virtual TAbstractScriptableObject*    AccessByProperty(const TAETransaction& t, DescType propertyIdentifier);
  276.  
  277.     // These accessors are used less frequently:
  278.     
  279.     TAbstractScriptableObject*            AccessByName(const TAETransaction& t, DescType desiredClass, TDescriptor nameDesc);
  280.     virtual TAbstractScriptableObject*    Access(const TAETransaction& t, DescType desiredClass, DescType keyForm, TDescriptor keyData);
  281.     virtual TAbstractScriptableObject*    AccessByUniqueID(const TAETransaction& t, DescType desiredClass, TDescriptor uniqueID);
  282.     virtual TAbstractScriptableObject*    AccessByOrdinal(const TAETransaction& t, DescType desiredClass, DescType ordinal);
  283.     virtual void                        AccessBySearchSpec(const TAETransaction& t, TAbstractCollector* collector, DescType desiredClass, TAbstractSearchSpec* searchSpec);
  284.     
  285.     // Methods relating to the data types accessible to this object
  286.     
  287.     virtual DescType                    BestType(const TAETransaction& t, DescType propertyName);
  288.     virtual DescType                    DefaultType(const TAETransaction& t, DescType propertyName);
  289.     virtual Boolean                        CanReturnDataOfType(const TAETransaction& t, DescType propertyName, DescType desiredType);
  290.     DescType                            DetermineDataTypeToReturn(const TAETransaction& t, DescType propertyName, TDescriptor requestedTypes);
  291.  
  292.     // Methods to override to provide data access to this object
  293.     
  294.             TDescriptor                    GetData(const TAETransaction& t, DescType requestedType);
  295.             void                        SetData(const TAETransaction& t, TDescriptor keyData);
  296.  
  297.             TDescriptor                    GetProperty(const TAETransaction& t, DescType propertyName, DescType desiredType);
  298.             void                        SetProperty(const TAETransaction& t, DescType propertyName, TDescriptor& data);
  299.  
  300.     virtual TDescriptor                    GetProperty(const TAETransaction& t, DescType propertyName, DescType desiredType, unsigned long additionalInfo);
  301.     virtual void                        SetProperty(const TAETransaction& t, DescType propertyName, TDescriptor& data, unsigned long additionalInfo);
  302.     
  303.     // Make an object specifier for this object
  304.     
  305.     TDescriptor                            BuildObjectSpecifierForProperty(const TAETransaction& t, DescType propertyName);
  306.     virtual TDescriptor                    BuildObjectSpecifier(const TAETransaction& transaction);
  307.     virtual void                        MakeKeyDataForSelf(const TAETransaction& t, DescType& keyForm, TDescriptor& keyData);
  308.     virtual TDescriptor                    BuildSpecifierForParent(const TAETransaction& transaction);
  309.  
  310.     virtual TDescriptor                    BuildSimpleSpecifier(const TAETransaction& transaction);
  311.  
  312.     // Event handlers
  313.     
  314.     virtual TDescriptor                    AECommand(const TAETransaction& t, long aeCommandID, TAbstractScriptableObject* auxObjects = nil, long auxInfo = 0);
  315.     virtual TAbstractScriptableObject*    CreateNewElement(const TAETransaction& t, DescType newObjectClass, TDescriptor initialData, TDescriptor initialProperties, Boolean& usedInitialData, Boolean& usedInitialProperties);
  316.         
  317.     // Get and set data and properties of this item
  318.     
  319.     TDescriptor                            GetDataGivenListOfTypes(const TAETransaction& t, DescType propertyName, TDescriptor listOfTypes, unsigned long additionalInfo = kLookupAdditionalInfo);
  320.     TDescriptor                            GetDataOfType(const TAETransaction& t, DescType propertyName, DescType requestedType, unsigned long additionalInfo = kLookupAdditionalInfo);
  321.     long                                GetDataSizeGivenListOfTypes(const TAETransaction& t, DescType propertyName, TDescriptor listOfRequestedTypes);
  322.     long                                GetDataSize(const TAETransaction& t, DescType propertyName, DescType requestedType);
  323.  
  324.     void                                SetProperties(const TAETransaction& t, TDescriptor& properties);
  325.     virtual TDescriptor                    GetProperties(const TAETransaction& t, DescType desiredType);
  326.     
  327.     // Used by Set Data handler to do intense voodoo magic
  328.     
  329.     TDescriptor                            ResolveSpecifierAndGetData(const TAETransaction& t, TDescriptor objectSpecifier);
  330.     TDescriptor                            ResolveKeyData(const TAETransaction& t, TDescriptor keyData);
  331.  
  332.     // Used by Get Data handler, more for convenience
  333.     
  334.     void                                CoerceResultToRequestedType(TDescriptor& result, DescType requestedType);
  335.  
  336.     // Compare this object with some other object
  337.  
  338.     Boolean                                CompareDescriptor(const TAETransaction& t, DescType comparisonOperator, TDescriptor& descOrObject);
  339.     Boolean                                Compare(const TAETransaction& t, DescType comparisonOperator, TAbstractScriptableObject* compareWith );
  340.     Boolean                                Compare(const TAETransaction& t, DescType comparisonOperator, TDescriptor& descOrObject );
  341.     
  342.     // Compare a property of this object with a descriptor
  343.     
  344.     virtual Boolean                        CompareProperty(const TAETransaction& t, DescType propertyIdentifier, DescType comparisonOperator, TDescriptor compareWith);
  345.     
  346.     // Parse whose descriptors
  347.     
  348.     TComparisonOperand*                    ParseComparisonOperand(TDescriptor& operand);
  349.     TAbstractSearchSpec*                ParseComparisonOperator(DescType comparisonOperator, TDescriptor& object1, TDescriptor& object2);
  350.     TAbstractSearchSpec*                ParseLogicalDescriptor(DescType logicalOperator, TDescriptor logicalTerms);
  351.     TAbstractSearchSpec*                ParseWhoseTest(TDescriptor& whoseDescriptor);
  352.     TAbstractSearchSpec*                ParseWhoseDescriptor(TDescriptor whoseDescriptor, TDescriptor& scopeOfSearch);
  353.         
  354.     // Event dispatching
  355.     
  356.     virtual TAbstractScriptableObject*    GetAECommandDispatcher(const TAETransaction& t, long commandID, long auxInfo, long& oneDispatchSelector);
  357.     virtual TDescriptor                    AECommandDispatch(const TAETransaction& t, long aeCommandID, long auxInfo = 0);
  358.  
  359.     // Glue for abstract references (not every scriptable object will have a reference object)
  360.     
  361.     virtual TAbstractScriptableObject*    ReturnReferencedObject();
  362.     virtual TAbstractReference*            CreateReference();
  363.     
  364.     virtual TAbstractScriptableObject*    RepresentativeScriptingObject(const TAETransaction& transaction);
  365.     virtual Boolean                        SendCommandToRepresentative(const TAETransaction& t, long aeCommandID);
  366.  
  367.     // Methods that determine if this object recognizes a certain property
  368.     
  369.     Boolean                                PropertyExists(const TAETransaction& t, DescType propertyName);
  370.     const TPropertyDescription*            DescriptionOfProperty(const TAETransaction& t, DescType propertyName);
  371.     long                                NumberOfProperties(const TAETransaction& t);
  372.     const TPropertyDescription*            DescriptionOfNthProperty(const TAETransaction& t, long propertyNumber);
  373.     
  374.     // Virtual access methods for mark tokens/proxy tokens
  375.     
  376.     virtual TAbstractObjectIterator*    DirectObjectIterator(const TAETransaction&);
  377.     AListOf<TAbstractScriptableObject*>*    ConvertThisToList(const TAETransaction& t, DescType useRepresentative = 0);
  378.     Boolean                                ObjectRepresentedInToken(const TAETransaction& t, TAbstractScriptableObject* objectToTestForMembership);
  379.     virtual Boolean                        ObjectsAreTheSame(const TAETransaction& t, TAbstractScriptableObject* objectToTest);
  380.     virtual TAbstractScriptableObject*    AdoptToken(TAbstractScriptableObject* token, TypeOfMarkToken markType);
  381.     virtual void                        AddThisToMarkToken(TAbstractScriptableObject*& markToken, TypeOfMarkToken markType);
  382.     };
  383.  
  384.  
  385. #endif
  386.